﻿//-----------------------------------------------------------------------
// <copyright file="ThreadNameClearer.cs">
//     Copyright (c) Nicole Calinoiu. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using System.Threading;

namespace Bordecal.FxCop.Sdk.Testing.AppDomainCustomization
{
	[Serializable]
	[SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented",
				Justification = "False positive.")]
	internal sealed class ThreadNameClearer : AppDomainCustomizer<object>
	{
		internal ThreadNameClearer()
		{
		}

		protected override object CreateDataValue()
		{
			return null;
		}

		protected override void DoCustomizeAppDomain(AppDomain targetDomain, object data)
		{
			FieldInfo nameField = typeof(Thread).GetField("m_Name", BindingFlags.Instance | BindingFlags.NonPublic);
			nameField.SetValue(Thread.CurrentThread, null, BindingFlags.Default, null, CultureInfo.InvariantCulture);
		}
	}
}